package com.xiaomage.view.draw4

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.view.View

/**
 * Created by Administrator on 2018/1/2.
 */
class CanvasClipView(context: Context): View(context) {
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        //定义画笔
        val paint= Paint()
        paint.isAntiAlias=true
        paint.style= Paint.Style.STROKE
        paint.strokeWidth=5f
        paint.color= Color.parseColor("#448ced")

        val paint2= Paint()
        paint2.color= Color.parseColor("#fc4c4f")
        paint2.isAntiAlias=true
        paint2.strokeWidth=5f
        paint2.style= Paint.Style.STROKE

        canvas.save()
        canvas.clipRect(Rect(0,0,600,600))
        canvas.drawColor(Color.GREEN)

        canvas.save()
        canvas.clipRect(Rect(100,100,500,500))
        canvas.drawColor(Color.YELLOW)

        canvas.save()
        canvas.clipRect(Rect(200,200,400,400))
        canvas.drawColor(Color.BLACK)

        canvas.save()
        canvas.clipRect(Rect(300,300,350,350))
        canvas.drawColor(Color.WHITE)

        canvas.restore()
        canvas.restore()
        canvas.restore()
        canvas.drawColor(Color.GRAY)




    }
}